# -*- coding: utf-8 -*-

import httplib
import urlparse

def request(url, cookie=''):
    ret = urlparse.urlparse(url)  # Parse input URL
    if ret.scheme == 'http':
        conn = httplib.HTTPConnection(ret.netloc)
    elif ret.scheme == 'https':
        conn = httplib.HTTPSConnection(ret.netloc)

    url = ret.path
    if ret.query: url += '?' + ret.query
    if ret.fragment: url += '#' + ret.fragment
    if not url: url = '/'

    conn.request(method='GET', url=url, headers={'Cookie': cookie})
    return conn.getresponse()


if __name__ == '__main__':
    # 每次获取10个国内代理地址，但是你需要检测代理有效性
    # 修改getnum参数
    cookie_str = 'tLargeScreenP=1; Authorization=Basic%20HereIsMySecret; subType=pcSub; TPLoginTimes=2'
    url = 'http://www.fldd.cn/api.asp?key=20160617162921076&getnum=10&filter=0&area=1&proxytype=0'

    json_str = request(url, cookie_str).read()
    print json_str

    # proxy_list = [
    #                {'http':"http://59.53.67.215:80"},
    #               {'http':"http://60.161.14.77:8001"},
    #               {'http':"http://61.144.14.68:80"},
    #               {'http':"http://61.144.68.180:9999"},
    #               {'http':"http://61.164.108.84:8844"},
    #               {'http':"http://61.166.55.153:11808"}
    #                ]